package com.cinnamon.rss.model;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="ITEMS")
public class Item implements Serializable{

	private static final long serialVersionUID = 1L;	

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="id")
	private long id;
	
	@Column(name="title")
	private String title;
	
	@Column(name="link")
	private String link;
	
	@Lob
	@Column(name="description")
	private String description;
	
	@Column(name="pubDate")
	private long pubDate;
	
	@Column(name="starFlag")
	private boolean starFlag;
	
	@Column(name="readFlag")
	private boolean readFlag;
	
	@Column(name="dateMark")
	private String dateMark;	
	
	public Item() {}
	
	public Item(String title, String link, String description,
			long pubDate) {
		
		this.title = title;
		this.link = link;
		this.description = description;
		this.pubDate = pubDate;
	}
	
	public Item(String title, String link, String description,
			long pubDate, boolean startFlag, boolean readFlag) {
		
		this.title = title;
		this.link = link;
		this.description = description;
		this.pubDate = pubDate;
		this.starFlag = startFlag;
		this.readFlag = readFlag;
	}

	public long getId() {
		return id;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getLink() {
		return link;
	}
	
	public void setLink(String link) {
		this.link = link;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}	
	
	public long getPubDate() {
		return pubDate;
	}

	public void setPubDate(long pubDate) {
		this.pubDate = pubDate;
	}

	public boolean isStartFlag() {
		return starFlag;
	}

	public void setStartFlag(boolean startFlag) {
		this.starFlag = startFlag;
	}

	public boolean isReadFlag() {
		return readFlag;
	}

	public void setReadFlag(boolean readFlag) {
		this.readFlag = readFlag;
	}
		
	public String getDateMark() {
		return dateMark;
	}

	public void setDateMark(String dateMark) {
		this.dateMark = dateMark;
	}

	@Override
	public String toString() {
		return "Item [id=" + id + ", title=" + title + ", link=" + link
				+ ", description=" + description + ", pubDate=" + pubDate
				+ ", startFlag=" + starFlag + ", readFlag=" + readFlag + "dateMark=" + dateMark;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (pubDate ^ (pubDate >>> 32));
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Item other = (Item) obj;
		if (pubDate != other.pubDate)
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		return true;
	}		
	
}
